home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1992 June: ROMin Holiday / ADC Developer CD (1992-06) (''ROMin Holiday'')_iso / Developer Connection - 06-1992.iso / Tools & Apps / Graphics & Imaging / Printer Drivers / STD File Saver 1.1 / MyPDEF_4_HandlingDialogs.p < prev    next >
Encoding:
Text File  |  1990-06-03  |  23.3 KB  |  762 lines  |  [TEXT/MPS ]

  1. unit MyPDEF_4_HandlingDialogs;
  2.  
  3. interface
  4.  
  5. uses MemTypes, QuickDraw, OsIntf, ToolIntf, PackIntf, MacPrint;
  6.  
  7. {$D+}
  8. {$R-}
  9. {$OV-}
  10.  
  11. procedure FilePrintDefault(hPrint: THPrint);
  12. function FilePrStlDialog(hPrint: THPrint): Boolean;
  13. function FilePrJobDialog(hPrint: THPrint): Boolean;
  14. function FilePrStlInit(hPrint: THPrint): TPPrDlg;
  15. function FilePrJobInit(hPrint: THPrint): TPPrDlg;
  16. function FilePrDlgMain(hPrint: THPrint; pDlgInit: ProcPtr): Boolean;
  17. function FilePrValidate(hPrint: THPrint): Boolean;
  18. procedure FilePrJobMerge(hPrintSrc, hPrintDst: THPrint);
  19. procedure HandleStlItems(theDlg: TPPrDlg; ItemHit: Integer);
  20. procedure HandleJobItems(theDlg: TPPrDlg; ItemHit: Integer);
  21. procedure SetDCV(theDialog: DialogPtr; theItem, theValue: Integer);
  22. function GetDCV(theDialog: DialogPtr; theItem: Integer): Integer;
  23. procedure SetDINb(theDialog: DialogPtr; theItem: Integer; theValue: Longint);
  24. function GetDINb(theDialog: DialogPtr; theItem: Integer): Longint;
  25. function GetDIRect(theDialog: DialogPtr; theItem: Integer): Rect;
  26. procedure SetDIStr(theDialog: DialogPtr; theItem: Integer; VAR theString: Str255);
  27. procedure GetDIStr(theDialog: DialogPtr; theItem: Integer; VAR theString: Str255);
  28. procedure SelDIStr(theDialog: DialogPtr; theItem: Integer);
  29.  
  30. implementation
  31.  
  32. const
  33.     ResLoad= $A5E;
  34.     PrintErr= $944;
  35.  
  36. type
  37.     BoolPtr= ^Boolean;
  38.     IntPtr= ^Integer;
  39.     LongPtr = ^Longint;
  40.     IntArr= array[0..0] of Integer;
  41.     IntArrPtr= ^IntArr;
  42.     IntArrHdl = ^IntArrPtr;
  43.  
  44. { 2 little inline routines to provide the correct call mechanism, nothing much ! }
  45. function CallFilePrXXXInit(hPrint: THPrint; theProc: ProcPtr): TPPrDlg;
  46.     inline $205F, $4E90; {MOVEA.L (A7)+,A0    ;    JSR (A0)}
  47.  
  48. procedure CallHandleXXXItems(thePrDlg: TPPrDlg; itemHit: Integer; pItemProc: ProcPtr);
  49.     inline $205F, $4E90; {MOVEA.L (A7)+,A0    ;    JSR (A0)}
  50.  
  51. procedure FilePrintDefault(hPrint: THPrint);
  52. { the default in is the resource PREC 0, and we also initialize some important fields }
  53. var
  54.     theDefault: THPrint;
  55.     resLoadStatus: Boolean;
  56.     
  57.     begin
  58.         resLoadStatus := BoolPtr(ResLoad)^;
  59.         if not resLoadStatus then SetResLoad(true);
  60.         theDefault := THPrint(GetResource('PREC', 0));
  61.         if not resLoadStatus then SetResLoad(false);
  62.         if theDefault = nil then
  63.             begin
  64.                 IntPtr(PrintErr)^ := -192;
  65.                 exit(FilePrintDefault);
  66.             end;
  67.         hPrint^^ := theDefault^^;
  68.         hPrint^^.prJob.iCopies := 1;
  69.         hPrint^^.prJob.pIdleProc := nil;
  70.         hPrint^^.prJob.pFileName := nil;
  71.         hPrint^^.prJob.iFileVol := 0;
  72.         hPrint^^.prJob.bFileVers := 0;
  73.         if StripAddress(Ptr(hPrint^)) <> StripAddress(Ptr(theDefault^)) then
  74.             ReleaseResource(Handle(theDefault));
  75.     end;
  76.  
  77. { for the 2 following routines, see Inside Macintosh vol. V and the relevant Technical Notes }
  78.  
  79. function FilePrStlDialog(hPrint: THPrint): Boolean;
  80.     begin
  81.         FilePrStlDialog := FilePrDlgMain(hPrint, @FilePrStlInit);
  82.     end;
  83.  
  84. function FilePrJobDialog(hPrint: THPrint): Boolean;
  85.     begin
  86.         FilePrJobDialog := FilePrDlgMain(hPrint, @FilePrJobInit);
  87.     end;
  88.  
  89. { 2 filter routines for the 3 dialogs: Style, Job and Options to set the Numeric Edit Fields right ! }
  90.  
  91. function FilterNumPrStlAndJob(theDialog: DialogPtr; VAR theEvent: EventRecord; VAR ItemHit: Integer): Boolean;
  92.     begin
  93.         FilterNumPrStlAndJob := false;
  94.         if theEvent.what in [keyDown, autoKey] then
  95.             if Band(theEvent.message, charCodeMask) in [$03, $0D] then
  96.                 begin
  97.                     ItemHit := 1;
  98.                     FilterNumPrStlAndJob := true;
  99.                     exit(FilterNumPrStlAndJob);
  100.                 end;
  101.         if theEvent.what in [keyDown, autoKey] then
  102.             if not (Band(theEvent.message, charCodeMask) in [$08, $09, $30..$39]) then
  103.                 begin
  104.                     SysBeep(1);
  105.                     FilterNumPrStlAndJob := true;
  106.                     ItemHit := -1;
  107.                     exit(FilterNumPrStlAndJob);
  108.                 end;
  109.     end;
  110.  
  111. function FilterNumOptions(theDialog: DialogPtr; VAR theEvent: EventRecord; VAR ItemHit: Integer): Boolean;
  112.     begin
  113.         FilterNumOptions := false;
  114.         if theEvent.what in [keyDown, autoKey] then
  115.             if Band(theEvent.message, charCodeMask) in [$03, $0D] then
  116.                 begin
  117.                     ItemHit := 1;
  118.                     FilterNumOptions := true;
  119.                     exit(FilterNumOptions);
  120.                 end;
  121.         if theEvent.what in [keyDown, autoKey] then
  122.             if (DialogPeek(theDialog)^.editField + 1) = 29 then
  123.                 if not (Band(theEvent.message, charCodeMask) in [$08, $09, $30..$39]) then
  124.                     begin
  125.                         SysBeep(1);
  126.                         FilterNumOptions := true;
  127.                         ItemHit := -1;
  128.                         exit(FilterNumOptions);
  129.                     end;
  130.     end;
  131.  
  132. function FilePrStlInit(hPrint: THPrint): TPPrDlg;
  133. { we initialize the dialog items with the right settings coming from hPrint }
  134. var
  135.     theDlg, aDlg: TPPrDlg;
  136.     i: Integer;
  137.     theRect: Rect;
  138.  
  139.     begin
  140.         FilePrStlInit := nil;
  141.         theDlg := TPPrDlg(NewPtr(sizeof(TPrDlg)));
  142.         if theDlg = nil then
  143.             begin
  144.                 IntPtr(PrintErr)^ := iMemFullErr;
  145.                 exit(FilePrStlInit);
  146.             end;
  147.         with theDlg^ do
  148.             begin
  149.                 aDlg := TPPrDlg(GetNewDialog(-8192, Ptr(theDlg), Pointer(-1)));
  150.                 if aDlg = nil then
  151.                     begin
  152.                         IntPtr(PrintErr)^ := -192;
  153.                         DisposPtr(Ptr(theDlg));
  154.                         exit(FilePrStlInit);
  155.                     end;
  156.                 SetDCV(DialogPtr(theDlg), 6, Ord(hPrint^^.printX[1] = 0));
  157.                 SetDCV(DialogPtr(theDlg), 7, Ord(hPrint^^.printX[1] = 1));
  158.                 SetDCV(DialogPtr(theDlg), 8, Ord(hPrint^^.printX[1] = 2));
  159.                 SetDINb(DialogPtr(theDlg), 13, hPrint^^.printX[2]);
  160.                 SetDINb(DialogPtr(theDlg), 20, hPrint^^.printX[3]);
  161.                 SetDINb(DialogPtr(theDlg), 21, hPrint^^.printX[4]);
  162.                 SetDCV(DialogPtr(theDlg), 22, Ord(hPrint^^.printX[5] = 0));
  163.                 SetDCV(DialogPtr(theDlg), 23, Ord(hPrint^^.printX[5] = 1));
  164.                 SetDCV(DialogPtr(theDlg), 24, Ord(hPrint^^.printX[5] = 2));
  165.                 if hPrint^^.printX[1] <> 2 then
  166.                     for i := 17 to 24 do HideDItem(DialogPtr(theDlg), i);
  167.                 pFltrProc := @FilterNumPrStlAndJob;
  168.                 pItemProc := @HandleStlItems;
  169.                 hPrintUsr := hPrint;
  170.                 ShowWindow(GrafPtr(theDlg));
  171.                 DrawDialog(GrafPtr(theDlg));
  172.                 SetPort(GrafPtr(theDlg));
  173.                 if hPrint^^.printX[6] = 0
  174.                     then theRect := GetDIRect(DialogPtr(theDlg), 9)
  175.                     else theRect := GetDIRect(DialogPtr(theDlg), 10);
  176.                 lUser1 := hPrint^^.printX[6];
  177.                 InvertRect(theRect);
  178.                 ValidRect(GrafPtr(theDlg)^.portRect);
  179.             end;
  180.         FilePrStlInit := theDlg;
  181.     end;
  182.  
  183. function FilePrJobInit(hPrint: THPrint): TPPrDlg;
  184. { we initialize the dialog items with the right settings coming from hPrint }
  185. var
  186.     aDlg, theDlg: TPPrDlg;
  187.     theWorld: SysEnvRec;
  188.     CodeErr: OsErr;
  189.  
  190.     begin
  191.         theDlg := TPPrDlg(NewPtr(sizeof(TPrDlg)));
  192.         if theDlg = nil then
  193.             begin
  194.                 IntPtr(PrintErr)^ := iMemFullErr;
  195.                 exit(FilePrJobInit);
  196.             end;
  197.         with theDlg^ do
  198.             begin
  199.                 aDlg := TPPrDlg(GetNewDialog(-8191, Ptr(theDlg), Pointer(-1)));
  200.                 if aDlg = nil then
  201.                     begin
  202.                         IntPtr(PrintErr)^ := -192;
  203.                         DisposPtr(Ptr(theDlg));
  204.                         exit(FilePrJobInit);
  205.                     end;
  206.                 CodeErr := SysEnvirons(1, theWorld);
  207.                 if not theWorld.hasColorQD then
  208.                     begin
  209.                         HideDItem(DialogPtr(theDlg), 14); HideDItem(DialogPtr(theDlg), 15);
  210.                         hPrint^^.printX[14] := 1;
  211.                     end;
  212.                 SetDCV(DialogPtr(theDlg), 5, Ord(hPrint^^.printX[7] = 0));
  213.                 SetDCV(DialogPtr(theDlg), 6, Ord(hPrint^^.printX[7] = 1));
  214.                 SetDCV(DialogPtr(theDlg), 12, Ord(hPrint^^.printX[8] = 0));
  215.                 SetDCV(DialogPtr(theDlg), 13, Ord(hPrint^^.printX[8] = 1));
  216.                 SetDCV(DialogPtr(theDlg), 14, Ord(hPrint^^.printX[14] = 0));
  217.                 SetDCV(DialogPtr(theDlg), 15, Ord(hPrint^^.printX[14] = 1));
  218.                 pFltrProc := @FilterNumPrStlAndJob;
  219.                 pItemProc := @HandleJobItems;
  220.                 hPrintUsr := hPrint;
  221.                 ShowWindow(GrafPtr(theDlg));
  222.                 SetPort(GrafPtr(theDlg));
  223.             end;
  224.         FilePrJobInit := theDlg;
  225.     end;
  226.  
  227. function FilePrDlgMain(hPrint: THPrint; pDlgInit: ProcPtr): Boolean;
  228. { see Inside Macintosh vol. V and the relevant Technical Notes }
  229. { we preload hPrint with the PREC 1 resource which is the last settings chosen by the user }
  230. { of course, after the user sets anew the values, we store them in the PREC 1 resource }
  231.  
  232. { Note: some applications pay attention to the PREC 1 mechanism, but not all of them }
  233. var
  234.     thePrDlg: TPPrDlg;
  235.     SavePort: GrafPtr;
  236.     itsBox: Rect;
  237.     itemHit: Integer;
  238.     resLoadStatus: Boolean;
  239.     theDefault: THPrint;
  240.     
  241.     begin
  242.         GetPort(SavePort);
  243.         resLoadStatus := BoolPtr(ResLoad)^;
  244.         if not resLoadStatus then SetResLoad(true);
  245.         theDefault := THPrint(GetResource('PREC', 1));
  246.         if not resLoadStatus then SetResLoad(false);
  247.         if theDefault <> nil then hPrint^^ := theDefault^^;
  248.         thePrDlg := CallFilePrXXXInit(hPrint, pDlgInit);
  249.         with thePrDlg^ do
  250.             begin
  251.                 fDone := false;
  252.                 fDoIt := false;
  253.                 itsBox := GetDIRect(DialogPtr(thePrDlg), 1);
  254.                 PenSize(3, 3);
  255.                 InsetRect(itsBox, -4, -4);
  256.                 FrameRoundRect(itsBox, 16, 16);
  257.                 while not fDone do
  258.                     begin
  259.                         ModalDialog(pFltrProc, itemHit);
  260.                         CallHandleXXXItems(thePrDlg, itemHit, pItemProc);
  261.                     end;
  262.                 SetPort(SavePort);
  263.                 CloseDialog(DialogPtr(thePrDlg));
  264.                 if fDoIt then { save in PREC 1 }
  265.                     begin
  266.                         resLoadStatus := BoolPtr(ResLoad)^;
  267.                         if not resLoadStatus then SetResLoad(true);
  268.                         theDefault := THPrint(GetResource('PREC', 1));
  269.                         if not resLoadStatus then SetResLoad(false);
  270.                         if theDefault <> nil then
  271.                             begin
  272.                                 theDefault^^ := hPrint^^;
  273.                                 ChangedResource(Handle(theDefault));
  274.                                 WriteResource(Handle(theDefault));
  275.                             end;
  276.                     end;
  277.                 FilePrDlgMain := fDoIt;
  278.                 DisposPtr(Ptr(thePrDlg));
  279.             end;
  280.     end;
  281.  
  282. function FilePrValidate(hPrint: THPrint): Boolean;
  283. { if the signature $5345 (ES) is present in the hPrint, then I consider that the values are ok }
  284. { else we just load anew the resource PREC 0 }
  285. { this alogrythm is not the best and could certainly be improved ! }
  286. var
  287.     theDefault: THPrint;
  288.     resLoadStatus: Boolean;
  289.     valid: Boolean;
  290.     i: Integer;
  291.     
  292.     begin
  293.         resLoadStatus := BoolPtr(ResLoad)^;
  294.         if not resLoadStatus then SetResLoad(true);
  295.         theDefault := THPrint(GetResource('PREC', 0));
  296.         if not resLoadStatus then SetResLoad(false);
  297.         if theDefault = nil then
  298.             begin
  299.                 IntPtr(PrintErr)^ := -192;
  300.                 exit(FilePrValidate);
  301.             end;
  302.         
  303.         valid := (hPrint^^.printX[9] = $5345);
  304.         if not valid then hPrint^^ := theDefault^^;
  305.         if StripAddress(Ptr(hPrint^)) <> StripAddress(Ptr(theDefault^)) then
  306.             ReleaseResource(Handle(theDefault));
  307.  
  308.         hPrint^^.prJob.iCopies := 1;
  309.         hPrint^^.prJob.pIdleProc := nil;
  310.         hPrint^^.prJob.pFileName := nil;
  311.         hPrint^^.prJob.iFileVol := 0;
  312.         hPrint^^.prJob.bFileVers := 0;
  313.  
  314.         FilePrValidate := valid;
  315.     end;
  316.  
  317. procedure FilePrJobMerge(hPrintSrc, hPrintDst: THPrint);
  318. { do we really want to manage this ? }
  319. { in fact, maybe we should in the case of a physical device printer driver }
  320.     begin
  321.     end;
  322.  
  323. procedure HandleStlItems(theDlg: TPPrDlg; ItemHit: Integer);
  324. { ok ! Here's just some dialog managing, and I won't bother you with the obvious ! }
  325. var
  326.     i, j, k: Integer;
  327.     theRect: Rect;
  328.     valid: Boolean;
  329.     height, width, rate: Longint;
  330.     optDlg: DialogPtr;
  331.     sigHandle: Handle;
  332.     sigTEXT, sigPICT: OsType;
  333.     aStr: Str255;
  334.     sigTab: array[1..14] of OsType;
  335.  
  336.     procedure RefreshDialog;
  337.     { redraw the frame around the ok button, and pay attention to the orientation icons }
  338.         begin
  339.             DrawDialog(DialogPtr(theDlg));
  340.             theRect := GetDIRect(DialogPtr(theDlg), 1);
  341.             PenSize(3, 3);
  342.             InsetRect(theRect, -4, -4);
  343.             FrameRoundRect(theRect, 16, 16);
  344.             
  345.             if theDlg^.lUser1 = 0
  346.                 then theRect := GetDIRect(DialogPtr(theDlg), 9)
  347.                 else theRect := GetDIRect(DialogPtr(theDlg), 10);
  348.             InvertRect(theRect);
  349.             ValidRect(GrafPtr(theDlg)^.portRect);
  350.         end;
  351.  
  352.     begin
  353.         with theDlg^ do
  354.             case ItemHit of
  355.                 ok:    begin
  356.                             valid := true;
  357.                             if GetDCV(DialogPtr(theDlg), 6) = 1 then
  358.                                 if lUser1 = 0
  359.                                     then begin width := 538; height := 781 end
  360.                                     else begin width := 781; height := 538 end
  361.                             else if GetDCV(DialogPtr(theDlg), 7) = 1 then
  362.                                 if lUser1 = 0
  363.                                     then begin width := 552; height := 730 end
  364.                                     else begin width := 730; height := 552 end
  365.                             else
  366.                                 begin
  367.                                     width := GetDINb(DialogPtr(theDlg), 20);
  368.                                     height := GetDINb(DialogPtr(theDlg), 21);
  369.                                     if lUser1 = 1 then
  370.                                         begin i := width; width := height; height := i; end;
  371.                                     if GetDCV(DialogPtr(theDlg), 22) = 1 then
  372.                                         begin
  373.                                             width := (width * 72) div 1000;
  374.                                             height := (height * 72) div 1000;
  375.                                         end
  376.                                     else if GetDCV(DialogPtr(theDlg), 23) = 1 then
  377.                                         begin
  378.                                             width := (width * 720) div 254;
  379.                                             height := (height * 720) div 254;
  380.                                         end;
  381.                                 end;
  382.                             rate := GetDINb(DialogPtr(theDlg), 13);
  383.                             if (rate > 0) and (rate <= 32767) then
  384.                                 begin
  385.                                     width := (width * 100) div rate;
  386.                                     height := (height * 100) div rate;
  387.                                 end
  388.                             else valid := false;
  389.                             if valid then valid := (width <> 0) and (height <> 0);
  390.                             if valid then with hPrintUsr^^ do
  391.                                 begin
  392.                                     SetRect(rPaper, 0, 0, width, height);
  393.                                     prInfo.rPage := rPaper;
  394.                                     prInfoPT.rPage := rPaper;
  395.                                     prStl.iPageV := (height * 120) div 72;
  396.                                     prStl.iPageH := (width * 120) div 72;
  397.                                     if GetDCV(DialogPtr(theDlg), 6) = 1 then printX[1] := 0;
  398.                                     if GetDCV(DialogPtr(theDlg), 7) = 1 then printX[1] := 1;
  399.                                     if GetDCV(DialogPtr(theDlg), 8) = 1 then printX[1] := 2;
  400.                                     printX[2] := GetDINb(DialogPtr(theDlg), 13);
  401.                                     printX[3] := GetDINb(DialogPtr(theDlg), 20);
  402.                                     printX[4] := GetDINb(DialogPtr(theDlg), 21);
  403.                                     if GetDCV(DialogPtr(theDlg), 22) = 1 then printX[5] := 0;
  404.                                     if GetDCV(DialogPtr(theDlg), 23) = 1 then printX[5] := 1;
  405.                                     if GetDCV(DialogPtr(theDlg), 24) = 1 then printX[5] := 2;
  406.                                     printX[6] := lUser1;
  407.                                     fDone := true;
  408.                                     fDoIt := true;
  409.                                 end
  410.                             else
  411.                                 begin
  412.                                     i := StopAlert(-8160, nil);
  413.                                     RefreshDialog;
  414.                                 end;
  415.                         end;
  416.                 cancel: begin fDone := true; fDoIt := false; end;
  417.                 6:    if GetDCV(DialogPtr(theDlg), ItemHit) = 0 then
  418.                         begin
  419.                             if GetDCV(DialogPtr(theDlg), 8) = 1 then
  420.                                 for i := 17 to 24 do HideDItem(DialogPtr(theDlg), i);
  421.                             SetDCV(DialogPtr(theDlg), 8, 0);
  422.                             SetDCV(DialogPtr(theDlg), 7, 0);
  423.                             SetDCV(DialogPtr(theDlg), 6, 1);
  424.                         end;
  425.                 7:    if GetDCV(DialogPtr(theDlg), ItemHit) = 0 then
  426.                         begin
  427.                             if GetDCV(DialogPtr(theDlg), 8) = 1 then
  428.                                 for i := 17 to 24 do HideDItem(DialogPtr(theDlg), i);
  429.                             SetDCV(DialogPtr(theDlg), 8, 0);
  430.                             SetDCV(DialogPtr(theDlg), 7, 1);
  431.                             SetDCV(DialogPtr(theDlg), 6, 0);
  432.                         end;
  433.                 8:    if GetDCV(DialogPtr(theDlg), ItemHit) = 0 then
  434.                         begin
  435.                             for i := 17 to 24 do ShowDItem(DialogPtr(theDlg), i);
  436.                             SetDCV(DialogPtr(theDlg), 8, 1);
  437.                             SetDCV(DialogPtr(theDlg), 7, 0);
  438.                             SetDCV(DialogPtr(theDlg), 6, 0);
  439.                         end;
  440.                 9,10:if lUser1+ItemHit = 10 then
  441.                         begin
  442.                             theRect := GetDIRect(DialogPtr(theDlg), 9); InvertRect(theRect);
  443.                             theRect := GetDIRect(DialogPtr(theDlg), 10); InvertRect(theRect);
  444.                             lUser1 := ItemHit-9;
  445.                         end;
  446.                 22..24:
  447.                     if GetDCV(DialogPtr(theDlg), ItemHit) = 0 then
  448.                         begin
  449.                             SetDCV(DialogPtr(theDlg), 22, 0);
  450.                             SetDCV(DialogPtr(theDlg), 23, 0);
  451.                             SetDCV(DialogPtr(theDlg), 24, 0);
  452.                             SetDCV(DialogPtr(theDlg), ItemHit, 1);
  453.                         end;
  454.                 25:    begin { here's the options dialog managing }
  455.                             sigHandle := GetResource('STR#', -8193);
  456.                             if sigHandle = nil then
  457.                                 begin
  458.                                     SysBeep(1);
  459.                                     exit(HandleStlItems);
  460.                                 end;
  461.                             for i := 1 to 14 do
  462.                                 begin
  463.                                     GetIndString(aStr, -8193, i);
  464.                                     BlockMove(Ptr(Longint(@aStr)+1), @sigTab[i], 4);
  465.                                 end;
  466.                             optDlg := GetNewDialog(-8193, nil, Pointer(-1));
  467.                             
  468.                             for i := 8 to 15 do SetDCV(optDlg, i, 0);
  469.                             for i := 17 to 24 do SetDCV(optDlg, i, 0);
  470.                             BlockMove(@hPrintUsr^^.printX[10], @sigTEXT, 4);
  471.                             BlockMove(@hPrintUsr^^.printX[12], @sigPICT, 4);
  472.                             j := 8; k := 15;
  473.                             for i := 1 to 7 do if sigPICT = sigTab[i] then j := i;
  474.                             for i := 8 to 14 do if sigTEXT = sigTab[i] then k := i;
  475.                             if j = 8 then
  476.                                 begin
  477.                                     SetDCV(optDlg, 15, 1);
  478.                                     aStr[0] := Chr(4);
  479.                                     BlockMove(@sigPICT, Ptr(Longint(@aStr)+1), 4);
  480.                                     SetDIStr(optDlg, 16, aStr);
  481.                                 end
  482.                             else SetDCV(optDlg, j+7, 1);
  483.                             if k = 15 then
  484.                                 begin
  485.                                     SetDCV(optDlg, 24, 1);
  486.                                     aStr[0] := Chr(4);
  487.                                     BlockMove(@sigTEXT, Ptr(Longint(@aStr)+1), 4);
  488.                                     SetDIStr(optDlg, 25, aStr);
  489.                                 end
  490.                             else SetDCV(optDlg, k+9, 1);
  491.                             
  492.                             SetDINb(optDlg, 29, LongPtr(@hPrintUsr^^.printX[15])^);
  493.                             SetDCV(optDlg, 31, ord(hPrintUsr^^.printX[17] = 0));
  494.  
  495.                             ShowWindow(optDlg);
  496.                             SetPort(optDlg);
  497.                             theRect := GetDIRect(DialogPtr(optDlg), 1);
  498.                             PenSize(3, 3);
  499.                             InsetRect(theRect, -4, -4);
  500.                             FrameRoundRect(theRect, 16, 16);
  501.                             SetPort(GrafPtr(theDlg));
  502.                             
  503.                             repeat
  504.                                 ModalDialog(@FilterNumOptions, ItemHit);
  505.                                 case ItemHit of
  506.                                     ok:begin
  507.                                             if j = 8 then
  508.                                                 begin
  509.                                                     GetDIStr(optDlg, 16, aStr);
  510.                                                     if Length(aStr) <> 4 then
  511.                                                         begin
  512.                                                             i := StopAlert(-8161, nil);
  513.                                                             SetPort(optDlg);
  514.                                                             theRect := GetDIRect(DialogPtr(optDlg), 1);
  515.                                                             PenSize(3, 3);
  516.                                                             InsetRect(theRect, -4, -4);
  517.                                                             FrameRoundRect(theRect, 16, 16);
  518.                                                             SetPort(GrafPtr(theDlg));
  519.                                                             SelDIStr(optDlg, 16);
  520.                                                             ItemHit := -1;
  521.                                                         end;
  522.                                                 end;
  523.                                             if k = 15 then
  524.                                                 begin
  525.                                                     GetDIStr(optDlg, 25, aStr);
  526.                                                     if Length(aStr) <> 4 then
  527.                                                         begin
  528.                                                             i := StopAlert(-8161, nil);
  529.                                                             SetPort(optDlg);
  530.                                                             theRect := GetDIRect(DialogPtr(optDlg), 1);
  531.                                                             PenSize(3, 3);
  532.                                                             InsetRect(theRect, -4, -4);
  533.                                                             FrameRoundRect(theRect, 16, 16);
  534.                                                             SetPort(GrafPtr(theDlg));
  535.                                                             SelDIStr(optDlg, 25);
  536.                                                             ItemHit := -1;
  537.                                                         end;
  538.                                                 end;
  539.                                             if GetDINb(optDlg, 29) <= 0 then
  540.                                                 begin        {this should never happen, but Murphy lives…}
  541.                                                     SysBeep(1);
  542.                                                     SelDIStr(optDlg, 29);
  543.                                                     ItemHit := -1;
  544.                                                 end;
  545.                                         end;
  546.                                     8..15:if j <> ItemHit-7 then
  547.                                                 begin
  548.                                                     SetDCV(optDlg, j+7, 0);
  549.                                                     j := ItemHit-7;
  550.                                                     SetDCV(optDlg, j+7, 1);
  551.                                                 end;
  552.                                     17..24:if k <> ItemHit-9 then
  553.                                                 begin
  554.                                                     SetDCV(optDlg, k+9, 0);
  555.                                                     k := ItemHit-9;
  556.                                                     SetDCV(optDlg, k+9, 1);
  557.                                                 end;
  558.                                     16,25:begin
  559.                                                 GetDIStr(optDlg, ItemHit, aStr);
  560.                                                 if Length(aStr) > 4 then
  561.                                                     begin
  562.                                                         SysBeep(1);
  563.                                                         aStr[0] := Chr(4);
  564.                                                         SetDIStr(optDlg, ItemHit, aStr);
  565.                                                     end;
  566.                                             end;
  567.                                     31: SetDCV(optDlg, ItemHit, 1 - GetDCV(optDlg, ItemHit));
  568.                                 end;
  569.                             until ItemHit in [ok, cancel];
  570.                             if ItemHit = ok then
  571.                                 begin
  572.                                     if j = 8 then
  573.                                         begin
  574.                                             GetDIStr(optDlg, 16, aStr);
  575.                                             BlockMove(Ptr(Longint(@aStr)+1), @hPrintUsr^^.printX[12], 4);
  576.                                         end
  577.                                     else BlockMove(@sigTab[j], @hPrintUsr^^.printX[12], 4);
  578.                                     if k = 15 then
  579.                                         begin
  580.                                             GetDIStr(optDlg, 25, aStr);
  581.                                             BlockMove(Ptr(Longint(@aStr)+1), @hPrintUsr^^.printX[10], 4);
  582.                                         end
  583.                                     else BlockMove(@sigTab[k], @hPrintUsr^^.printX[10], 4);
  584.                                     rate := GetDINb(optDlg, 29);
  585.                                     BlockMove(@rate, @hPrintUsr^^.printX[15], 4);
  586.                                     hPrintUsr^^.printX[17] := 1 - GetDCV(optDlg, 31);
  587.                                 end;
  588.                             DisposDialog(optDlg);
  589.                             ReleaseResource(sigHandle);
  590.                             
  591.                             RefreshDialog;
  592.                         end;
  593.                 26:    begin { here's the help dialog managing }
  594.                             optDlg := GetNewDialog(-8194, nil, Pointer(-1));
  595.  
  596.                             for i := 6 to 11 do HideDItem(optDlg, i);
  597.                             ShowWindow(optDlg);
  598.                             DrawDialog(optDlg);
  599.                             SetPort(optDlg);
  600.                             ValidRect(optDlg^.portRect);
  601.                             TextFont(Geneva);
  602.                             TextSize(9);
  603.                             for i := 6 to 11 do ShowDItem(optDlg, i);
  604.                             theRect := GetDIRect(DialogPtr(optDlg), 1);
  605.                             PenSize(3, 3);
  606.                             InsetRect(theRect, -4, -4);
  607.                             FrameRoundRect(theRect, 16, 16);
  608.                             SetPort(GrafPtr(theDlg));
  609.                             
  610.                             repeat
  611.                                 ModalDialog(nil, ItemHit);
  612.                             until ItemHit = ok;
  613.                             DisposDialog(optDlg);
  614.                             
  615.                             RefreshDialog;
  616.                         end;
  617.             end;
  618.     end;
  619.  
  620. procedure HandleJobItems(theDlg: TPPrDlg; ItemHit: Integer);
  621. { ok ! Here's just some dialog managing, and I won't bother you with the obvious ! }
  622.     begin
  623.         with theDlg^ do
  624.             case ItemHit of
  625.                 ok:with hPrintUsr^^ do
  626.                         begin
  627.                             if GetDCV(DialogPtr(theDlg), 5) = 0 then
  628.                                 begin
  629.                                     prJob.iFstPage := GetDINb(DialogPtr(theDlg), 7);
  630.                                     prJob.iLstPage := GetDINb(DialogPtr(theDlg), 9);
  631.                                     printX[7] := 1;
  632.                                 end
  633.                             else
  634.                                 begin
  635.                                     prJob.iFstPage := 1;
  636.                                     prJob.iLstPage := 9999;
  637.                                     printX[7] := 0;
  638.                                 end;
  639.                             if GetDCV(DialogPtr(theDlg), 12) = 0
  640.                                 then printX[8] := 1
  641.                                 else printX[8] := 0;
  642.                             if GetDCV(DialogPtr(theDlg), 14) = 0
  643.                                 then printX[14] := 1
  644.                                 else printX[14] := 0;
  645.                             fDone := true; fDoIt := true;
  646.                         end;
  647.                 cancel: begin fDone := true; fDoIt := false; end;
  648.                 5, 6:    if GetDCV(DialogPtr(theDlg), ItemHit) = 0 then
  649.                             begin
  650.                                 SetDCV(DialogPtr(theDlg), ItemHit, 1);
  651.                                 SetDCV(DialogPtr(theDlg), 11 - ItemHit, 0);
  652.                             end;
  653.                 7, 9:    if GetDCV(DialogPtr(theDlg), 6) = 0 then
  654.                             begin
  655.                                 SetDCV(DialogPtr(theDlg), 6, 1);
  656.                                 SetDCV(DialogPtr(theDlg), 5, 0);
  657.                             end;
  658.                 12,13:if GetDCV(DialogPtr(theDlg), ItemHit) = 0 then
  659.                             begin
  660.                                 SetDCV(DialogPtr(theDlg), ItemHit, 1);
  661.                                 SetDCV(DialogPtr(theDlg), 25 - ItemHit, 0);
  662.                             end;
  663.                 14,15:if GetDCV(DialogPtr(theDlg), ItemHit) = 0 then
  664.                             begin
  665.                                 SetDCV(DialogPtr(theDlg), ItemHit, 1);
  666.                                 SetDCV(DialogPtr(theDlg), 29 - ItemHit, 0);
  667.                             end;
  668.             end;
  669.     end;
  670.  
  671. { here are some useful and convenient routines to ease the dialog managing }
  672.  
  673. procedure SetDCV(theDialog: DialogPtr; theItem, theValue: Integer);
  674. var
  675.     theType: Integer;
  676.     theHandle: Handle;
  677.     theRect: Rect;
  678.  
  679.     begin
  680.         GetDItem(theDialog, theItem, theType, theHandle, theRect);
  681.         SetCtlValue(ControlHandle(theHandle), theValue);
  682.     end;
  683.  
  684. function GetDCV(theDialog: DialogPtr; theItem: Integer): Integer;
  685. var
  686.     theType: Integer;
  687.     theHandle: Handle;
  688.     theRect: Rect;
  689.  
  690.     begin
  691.         GetDItem(theDialog, theItem, theType, theHandle, theRect);
  692.         GetDCV := GetCtlValue(ControlHandle(theHandle));
  693.     end;
  694.  
  695. procedure SetDINb(theDialog: DialogPtr; theItem: Integer; theValue: Longint);
  696. var
  697.     theType: Integer;
  698.     theHandle: Handle;
  699.     theRect: Rect;
  700.     theStr: Str255;
  701.  
  702.     begin
  703.         GetDItem(theDialog, theItem, theType, theHandle, theRect);
  704.         NumToString(theValue, theStr);
  705.         SetIText(theHandle, theStr);
  706.     end;
  707.  
  708. function GetDINb(theDialog: DialogPtr; theItem: Integer): Longint;
  709. var
  710.     theType: Integer;
  711.     theHandle: Handle;
  712.     theRect: Rect;
  713.     theStr: Str255;
  714.     theValue: Longint;
  715.  
  716.     begin
  717.         GetDItem(theDialog, theItem, theType, theHandle, theRect);
  718.         GetIText(theHandle, theStr);
  719.         StringToNum(theStr, theValue);
  720.         GetDINb := theValue;
  721.     end;
  722.  
  723. function GetDIRect(theDialog: DialogPtr; theItem: Integer): Rect;
  724. var
  725.     theType: Integer;
  726.     theHandle: Handle;
  727.     theRect: Rect;
  728.  
  729.     begin
  730.         GetDItem(theDialog, theItem, theType, theHandle, theRect);
  731.         GetDIRect := theRect;
  732.     end;
  733.  
  734. procedure SetDIStr(theDialog: DialogPtr; theItem: Integer; VAR theString: Str255);
  735. var
  736.     theType: Integer;
  737.     theHandle: Handle;
  738.     theRect: Rect;
  739.  
  740.     begin
  741.         GetDItem(theDialog, theItem, theType, theHandle, theRect);
  742.         SetIText(theHandle, theString);
  743.     end;
  744.  
  745. procedure GetDIStr(theDialog: DialogPtr; theItem: Integer; VAR theString: Str255);
  746. var
  747.     theType: Integer;
  748.     theHandle: Handle;
  749.     theRect: Rect;
  750.  
  751.     begin
  752.         GetDItem(theDialog, theItem, theType, theHandle, theRect);
  753.         GetIText(theHandle, theString);
  754.     end;
  755.  
  756. procedure SelDIStr(theDialog: DialogPtr; theItem: Integer);
  757.     begin
  758.         SelIText(theDialog, theItem, 0, 32767);
  759.     end;
  760.  
  761. end.
  762.